# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jeffrey Zhang <zhang.lei.fly@gmail.com>

_name=pytest-lsp
pkgname=python-pytest-lsp
pkgver=0.2.1
pkgrel=2
pkgdesc='Pytest plugin for end-to-end testing of language servers'
arch=('any')
url=https://swyddfa.github.io/lsp-devtools
license=('MIT')
depends=('python-appdirs' 'python-pygls' 'python-pytest-asyncio')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
source=("https://github.com/swyddfa/lsp-devtools/archive/pytest-lsp-v$pkgver/$_name-$pkgver.tar.gz")
b2sums=('de9cf14c37e6be093cbb16628edfa8afbc42ffad637174cb0f3db28138924283c381e5a995e67ab593a46cc3c58cc06e049d2c756f8633336ba8c94e08c42f2d')

build() {
  cd lsp-devtools-pytest-lsp-v$pkgver/lib/pytest-lsp
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd lsp-devtools-pytest-lsp-v$pkgver/lib/pytest-lsp
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

package() {
  cd lsp-devtools-pytest-lsp-v$pkgver/lib/pytest-lsp
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/pytest_lsp-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
